<template>
    <Layout>
        <Spin fix v-if="isSpin">
            <Icon type="ios-loading" size=18 class="demo-spin-icon-load"></Icon>
            <div>正在生成处罚通知单，请稍后</div>
        </Spin>
        <Form ref="form1" :model="form1" :label-width="120">
            <Row v-show="!switchFlag" class="query-form">
                <Col span="8">
                    <FormItem label="工程名称：">
                        <Input v-model="form1.projectName" type="text"/>
                    </FormItem>
                </Col>
                <Col span="8" offset="8">
                    <Button @click="reset" class="ivu-btn-reset">重置</Button>
                    <Button class="ivu-btn-query" icon="md-search" @click="query">查询</Button>
                </Col>
            </Row>
            <Row class="query-form">
                <Col span="24">
                    <Button size="large" class="ivu-btn-add" icon="md-add" @click="addInfo">新增</Button>
                </Col>
            </Row>
        </Form>

        <Table ref='table' :height="tableHeight" size="small" :loading="loading" no-data-text="没有查询到相关数据!"
               @on-selection-change='getSelectRows'
               border :columns="columns1" :data="dataTable">
        </Table>
        <Row style="margin-right:10px;">
            <Col span="24">
                <Page style="float: right" :total="pagedata.total" :page-size="pagedata.pageSize"
                      @on-change="pageChange" @on-page-size-change="pageSizeChange" :page-size-opts="pageSizeArray"
                      show-total show-sizer show-elevator/>
            </Col>
        </Row>
        <Modal :title="add?'安全环保处罚通知单新增':'安全环保处罚通知单修改'" :transfer=false v-model="model1" :width="1000" @on-cancal="handleCancel">
            <Row>
                <Col span="24">
                    <Form ref="form1datacopy" :model="form1datacopy" :rules="ruleCustom" label-position="top">
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label="工程名称：" prop="projectName">
                                    <Input v-model="form1datacopy.projectName" type="text"/>
                                </FormItem>
                            </Col>

                            <Col span="11">
                                <FormItem label="施工单位：" prop="constructionUnit">
                                    <Input v-model="form1datacopy.constructionUnit" type="text"/>
                                </FormItem>
                            </Col>
                        </Row>
						<Row type="flex" justify="space-around" class="code-row-bg">
						    <Col span="11">
						        <FormItem label="罚款金额(小写)元：" prop="fineLower">
									<InputNumber class='w' :min="0" :active-change='false' :precision="2" placeholder="请填写罚款金额(小写),整数最大为十位"  type='text' v-model='form1datacopy.fineLower' @on-change='convertUpper'></InputNumber>
						        </FormItem>
						    </Col>
						    <Col span="11">
						        <FormItem label="罚款金额(大写)：" prop="fineUpper">
						            <Input v-model="form1datacopy.fineUpper" type="text" disabled/>
						        </FormItem>
						    </Col>
						</Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="23">
                                <FormItem label="罚款事由：" prop="punishReason">
                                    <Input v-model="form1datacopy.punishReason" type="textarea"/>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label="签发人(建设单位)：" prop="issuer">
                                    <Input v-model="form1datacopy.issuer" type="text"/>
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label="签收人(施工单位)：" prop="receiver">
                                    <Input v-model="form1datacopy.receiver" type="text"/>
                                </FormItem>
                            </Col>
                        </Row>
						<Row type="flex" justify="space-around" class="code-row-bg">
						    <Col span="23">
						        <FormItem label="备注：" prop="remarks">
						            <Input v-model="form1datacopy.remarks" type='textarea'/>
						        </FormItem>
						    </Col>
						</Row>
						<Row type="flex" justify="space-around" class="code-row-bg">
						    <Col span="23">
						        <FormItem label="上传照片：">
						            <div>
						                <Upload ref="upload"
						                        :before-upload="beforeUpload"
						                        :show-upload-list="true"
						                        :max-size="10240"
						                        accept="image/jpg, image/jpeg,image/png,image/gif,image/bmp"
						                        multiple
						                        type="drag"
						                        :action="fileUrl">
						                    <div style="padding: 10px">
						                        <Icon type="ios-cloud-upload" size="45" style="color: #F27874"></Icon>
						                        <p>点击将文件拖拽到这里上传</p>
						                        <span style="font-size:8px;color: #797a64">支持扩展名：.jpg，jpeg，png 格式的图片</span>
						                    </div>
						                </Upload>
						            </div>
									<div v-show="uploadList.length>0" v-for="item in uploadList" :key='item.id' style="display: inline-block;margin-right: 10px">
									    <a @click="downloadFile(form1datacopy.id,item)">{{ item.fileName }}</a>
									    <Button type="text" icon="md-trash" @click="remove1(item.id,form1datacopy.id)"
									            style="margin-left: 5px;margin-bottom: 3px"/>
									</div>
						        </FormItem>
						    </Col>
						</Row>
                    </Form>
                </Col>
            </Row>
            <div slot="footer">
                <Button :disabled="saveMod" class='ivu-btn-save' :loading="buttonLoading"
                        @click="submit('form1datacopy')">确定
                </Button>
                <Button class='ivu-btn-cancel' @click="handleCancel">取消</Button>
            </div>
        </Modal>
        <Modal title="安全环保处罚通知单详情" :transfer='false' v-model="model2" :width="1000" class="modal-view-detail" @on-cancal="handleCancel">
            <Row>
                <Col span="24">
                    <Form :model="form1datacopy" :label-width="160">
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label="工程名称：" prop="projectName">
                                    {{form1datacopy.projectName}}
                                </FormItem>
                            </Col>
							<Col span="11">
							    <FormItem label="施工单位：" prop="constructionUnit">
									{{form1datacopy.constructionUnit}}
							    </FormItem>
							</Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label="罚款金额(小写)元：" prop="fineLower">
                                    {{form1datacopy.fineLower}}
                                </FormItem>
                            </Col>
							<Col span="11">
							    <FormItem label="罚款金额(大写)：" prop="fineUpper">
									{{form1datacopy.fineUpper}}
							    </FormItem>
							</Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="23">
                                <FormItem label="罚款事由：" prop="punishReason">
									{{form1datacopy.punishReason}}
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label="签发人(建设单位)：" prop="issuer">
									{{form1datacopy.issuer}}
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label="签收人(施工单位)：" prop="receiver">
                                    {{form1datacopy.receiver}}
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="23">
                                <FormItem label="备注：" prop="remarks">
                                    {{form1datacopy.remarks}}
                                </FormItem>
                            </Col>
                        </Row>
                        <!-- <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="23">
                                <FormItem label="签发人(单位)签字：">
                                    <div v-show="inspectionPersonnelFileList.length>0" v-for="item in inspectionPersonnelFileList" :key='item.id'  style="display: inline-block;margin-right: 10px">
                                        <router-link target="_blank" :to="{path:'/imgDetails',query:{id:item.id}}">
                                            <img :src="item.picture" alt="" style="width: 50px;height: 50px;">
                                        </router-link>
                                        <br>
                                        <a @click="downloadFile(form1datacopy.inspectionPersonnelFile,item)">{{ item.fileName }}</a>
                                    </div>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="23">
                                <FormItem label="签收人(单位)签字：">
                                    <div v-show="projectLeaderFileList.length>0" v-for="item in projectLeaderFileList" :key='item.id'  style="display: inline-block;margin-right: 10px">
                                        <router-link target="_blank" :to="{path:'/imgDetails',query:{id:item.id}}">
                                            <img :src="item.picture" alt="" style="width: 50px;height: 50px;">
                                        </router-link>
                                        <br>
                                        <a @click="downloadFile(form1datacopy.projectLeaderFile,item)">{{ item.fileName }}</a>
                                    </div>
                                </FormItem>
                            </Col>
                        </Row> -->
						<Row class="detail-background-clor" style="line-height: 42px;">
						    <Col span="23">
						        <FormItem label="照片：">
						            <div v-show="uploadList.length>0" v-for="(item,index) in uploadList" :key="index" style="display: inline-block;margin-right: 10px">
						                <router-link target="_blank" :to="{path:'/imgDetails',query:{id:item.id}}">
						                    <img :src="item.picture" alt="" style="width: 50px;height: 50px;">
						                </router-link>
						                <br><br>
						                <a @click="downloadFile(form1datacopy.id,item)">{{ item.fileName }}</a>
						            </div>
						        </FormItem>
						    </Col>
						</Row>
                    </Form>
                </Col>
            </Row>
            <div slot="footer">
                <Button class='ivu-btn-save' @click="handleCancel">关闭</Button>
            </div>
        </Modal>
    </Layout>
</template>

<script>
    import {Api} from '../../../api'
    import {sessionStorage} from '../../../common/cacheUtils.js';
    import cascaderDom from '../../../components/cascader-dom.vue';
	import pageCommonFunction from '@/components/pageCommonFunction.js'

    export default {
        components: {
            cascaderDom
        },
        data() {
            return {
				currentUser: JSON.parse(sessionStorage('userId').get('userId')),
				...this.createCommonDataField(),
				id: this.get_uuid(),
				// itemId: id,
                isSpin: false,
                // apsgNoticeItem: [],
                companyId: sessionStorage('userId').getObject('userId').companyId,
                appDate: ["", ""],
                appStatusList: [],
                fileUrl: Api.interestedPartiesUserFile,
                locationList: [],
                stdRankList: [],
                inspectionPersonnelFileList:[],
                projectLeaderFileList:[],
                index:null,
                downloadUrl: Api.downloadMongoFile,
                upUrl: Api.uploadMongoFile,
                switchFlag: false,
                saveMod: false,
                form1: {},
                uploadList: [],
                model5:false,
                InputItemData:{},
                ruleCustom1:{},
                pageSizeArray: [10, 20, 50],
                pagedata: {
                    total: 0,
                    pageSize: 10,
                    currentPage: 1,
                },
                dataTable: [],
                columns1: [
                    {
                        title: "序号",
                        width: 80,
                        align: "center",
                        fixed: 'left',
                        render: (h, params) => {
                            return h('span', params.index + (this.pagedata.currentPage - 1) * this.pagedata.pageSize + 1);
                        }
                    },
                    {
                        title: '工程名称',
                        minWidth: 260,
                        align: 'center',
                        key: 'projectName',
                    },
                    {
                        title: '施工单位',
                        minWidth: 260,
                        align: 'center',
                        key: 'constructionUnit',
                    },
					{
					    title: '罚款金额(元)',
					    minWidth: 150,
					    align: 'center',
					    key: 'fineLower',
					},
                    {
                        title: '罚款事由',
                        minWidth: 200,
                        align: 'center',
                        key: 'punishReason',
						tooltip:true,
                    },
                    {
                        title: '签发人(建设单位)',
                        minWidth: 200,
                        align: 'center',
                        key: 'issuer',
                    },
                    {
                        title: '签收人(施工单位)',
                        minWidth: 200,
                        align: 'center',
                        key: 'receiver',
                    },
                    {
                        title: '创建时间',
                        minWidth: 150,
                        align: 'center',
                        key: 'createDate',
                        render: (h, params) => {
                            return h('div', [
                                (this.formatDate(new Date(params.row.createDate), 'yyyy-MM-dd'))
                            ]);
                        }
                    },
                    {
                        title: '操作',
                        key: 'action',
                        fixed: 'right',
                        width: 250,
                        align: 'center',
                        render: (h, params) => {
							let currentUser=JSON.parse(sessionStorage('userId').get('userId'));
							if(currentUser.loginId === this.Common.admin || currentUser.userId === params.row.createUserId  || currentUser.userRole.find(obj => obj.roleId == '73b38b37dff64392ba0ee7dd579bf293') != undefined){
								return h('div', [
								    h('A', {
								        props: {
								            type: 'primary',
								            size: 'small'
								        },
								        style: {
								            fontSize: '14px',
								        },
								        on: {
								            click: () => {
								                this.showData(params, 1);
								            }
								        }
								    }, '详情'),
								    h('Divider', {
								        props: {
								            type: 'vertical',
								        }
								    }, ''),
								    h('A', {
								        props: {
								            type: 'primary',
								            size: 'small'
								        },
										disabled: true,
								        style: {
								            fontSize: '14px',
								        },
								        on: {
								            click: () => {
								                this.showData(params, 2);
								            }
								        }
								    }, '修改'),
								    h('Divider', {
								        props: {
								            type: 'vertical',
								        }
								    }, ''),
								    h('A', {
								        props: {
								            type: 'primary',
								            size: 'small'
								        },
										disabled:true,
								        style: {
								            fontSize: '14px',
								            color: 'red',
								        },
								        on: {
								            click: () => {
								
								                this.$Modal.confirm({
								                    title: '数据删除',
								                    content: '<p>确定删除该条信息</p>',
								                    okText: '确认',
								                    onOk: () => {
								                        this.deleteData(params);
								                    },
								                    cancelText: '取消'
								                });
								
								            }
								        }
								    }, '删除'),
								    h('Divider', {
								        props: {
								            type: 'vertical',
								        }
								    }, ''),
								    h('A', {
								        props: {
								            type: 'error',
								            size: 'small'
								        },
								        style: {
								            fontSize: '14px',
								        },
								        on: {
								            click: () => {
								                this.export(params.row)
								            }
								        }
								    }, '下载处罚单')
								]);
							}else{
								return h('div', [
								    h('A', {
								        props: {
								            type: 'primary',
								            size: 'small'
								        },
								        style: {
								            fontSize: '14px',
								        },
								        on: {
								            click: () => {
								                this.showData(params, 1);
								            }
								        }
								    }, '详情'),
								    h('Divider', {
								        props: {
								            type: 'vertical',
								        }
								    }, ''),
								    h('A', {
								        props: {
								            type: 'primary',
								            size: 'small'
								        },
								        style: {
								            fontSize: '14px',
											color: '#c5c8ce'
								        },
								    }, '修改'),
								    h('Divider', {
								        props: {
								            type: 'vertical',
								        }
								    }, ''),
								    h('A', {
								        props: {
								            type: 'primary',
								            size: 'small'
								        },
								        style: {
								            fontSize: '14px',
								            color: '#c5c8ce'
								        }
								    }, '删除'),
								    h('Divider', {
								        props: {
								            type: 'vertical',
								        }
								    }, ''),
								    h('A', {
								        props: {
								            type: 'error',
								            size: 'small'
								        },
								        style: {
								            fontSize: '14px',
								        },
								        on: {
								            click: () => {
								                this.export(params.row)
								            }
								        }
								    }, '下载处罚单')
								]);
							}
                            // return h('div', [
                            //     h('A', {
                            //         props: {
                            //             type: 'primary',
                            //             size: 'small'
                            //         },
                            //         style: {
                            //             fontSize: '14px',
                            //         },
                            //         on: {
                            //             click: () => {
                            //                 this.showData(params, 1);
                            //             }
                            //         }
                            //     }, '详情'),
                            //     h('Divider', {
                            //         props: {
                            //             type: 'vertical',
                            //         }
                            //     }, ''),
                            //     h('A', {
                            //         props: {
                            //             type: 'primary',
                            //             size: 'small'
                            //         },
                            //         style: {
                            //             fontSize: '14px',
                            //         },
                            //         on: {
                            //             click: () => {
                            //                 this.showData(params, 2);
                            //             }
                            //         }
                            //     }, '修改'),
                            //     h('Divider', {
                            //         props: {
                            //             type: 'vertical',
                            //         }
                            //     }, ''),
                            //     h('A', {
                            //         props: {
                            //             type: 'primary',
                            //             size: 'small'
                            //         },
                            //         style: {
                            //             fontSize: '14px',
                            //             color: 'red',
                            //         },
                            //         on: {
                            //             click: () => {

                            //                 this.$Modal.confirm({
                            //                     title: '数据删除',
                            //                     content: '<p>确定删除该条信息</p>',
                            //                     okText: '确认',
                            //                     onOk: () => {
                            //                         this.deleteData(params);
                            //                     },
                            //                     cancelText: '取消'
                            //                 });

                            //             }
                            //         }
                            //     }, '删除'),
                            //     h('Divider', {
                            //         props: {
                            //             type: 'vertical',
                            //         }
                            //     }, ''),
                            //     h('A', {
                            //         props: {
                            //             type: 'error',
                            //             size: 'small'
                            //         },
                            //         style: {
                            //             fontSize: '14px',
                            //         },
                            //         on: {
                            //             click: () => {
                            //                 this.export(params.row)
                            //             }
                            //         }
                            //     }, '下载处罚单')
                            // ]);
                        }
                    },

                ],
                view:false,
                ruleCustom: {
                    projectName: [{
                        validator: (rule, value, callback) => {
                            if (this.form1datacopy.projectName == null || this.form1datacopy.projectName == '' || this.form1datacopy.projectName == undefined) {
                                callback(' ')
                            } else {
                                callback()
                            }
                        },
                        required: true,
                        trigger: 'change'
                    }],
                    constructionUnit: [{
                        validator: (rule, value, callback) => {
                            if (this.form1datacopy.constructionUnit == null || this.form1datacopy.constructionUnit == '' || this.form1datacopy.constructionUnit == undefined) {
                                callback(' ')
                            } else {
                                callback()
                            }
                        },
                        required: true,
                        trigger: 'change'
                    }],
					fineLower: [ { pattern: /^(([1-9]\d*)|0)(\.\d{1,2})?$/, required: true, message: '请填写罚款金额(小写),整数最大为十位', trigger: 'change, blur',type: 'number'}],
					punishReason: [ { required: true, message: ' ', trigger: 'change' } ],
                },
                model4:false,
                stdOrgName: '',
                stdOrgId: '',
                add: false,
                model1: false,
                buttonLoading: false, model2: false,
                showdata: {},
                location: null,
                form1datacopy: {},
                files: [],
                loading1:false,
                addItem:false,
                tableHeight: 10, loading: false,
            }
        },
        mounted() {
            this.tableHeight = window.innerHeight - this.$refs.table.$el.offsetTop - 145;
            let orgId = sessionStorage('userId').getObject('userId')
            this.query();
        },
        computed: {
            columns10() {
                const columns = [...this.columns3];
                const columns10=[]
                columns.forEach(item=>{
                    if (item.title != '操作'){
                        columns10.push(item)
                    }else{
                        console.log(item);
                    }
                });
                return columns10
            },
        },
        methods: {
			...pageCommonFunction,
            getFiles(id) {
                let url = this.fileUrl + '/' + id + '/files/picture'
                this.$http.get(url).then((res) => {
                    if (res.data.result == "success") {
                        this.uploadList  = res.data.data
                    }
                })
            },

            getFiles1(id,str) {
                let url = this.fileUrl + '/' + id + '/files/picture'
                this.$http.get(url).then((res) => {
                    if (res.data.result == "success") {
                        if (str === "1"){
                            this.inspectionPersonnelFileList  = res.data.data
                        } else if(str === "2") {
                            this.projectLeaderFileList  = res.data.data
                        }
                        this.uploadList  = res.data.data
                    }
                })
            },
            getFile(id){
                let hFn = [];
                let files = [];
                let url = this.fileUrl + '/' + id + '/files/picture'
                this.$http.get(url).then((res) => {
                    if (res.data.result == "success") {
                        files  = res.data.data
                        params.row.files.forEach(v => {
                            if (v) {
                                hFn.push(
                                    h('img', {
                                        style: {
                                            width: "30px",
                                            margin: "3px",
                                            cursor: "pointer"
                                        },
                                        attrs: {
                                            src: v.picture
                                        }
                                    })
                                )
                            }
                        });
                        return hFn
                    }
                })

            },
			//上传
            beforeUpload(file) {
                var index = file.name.lastIndexOf(".");
                var suffix = file.name.substr(index + 1);
				if(this.add){
					this.InputItemData = {
					    itemId:this.id,
					    files:[],
					};
				}else{
					this.InputItemData = {
					    itemId:this.form1datacopy.id,
					    files:[],
					};
				}
                if (suffix != 'jpg' && suffix != 'jpeg' && suffix != 'png') {
                    this.$Message.error("请上传jpg,jpeg,png格式的图片");
                    this.file = null;
                    this.fileName = null;
                } else {
                    let formData = new FormData();
                    formData.append("files", file); // 文件对象
                    let url = this.fileUrl + '/' +this.InputItemData.itemId + '/files/picture'
                    this.$http.post(url, formData).then((res) => {
                        if (res.data.result == "success") {
                            this.$Message.info("文件上传成功")
                            this.getFiles(this.InputItemData.itemId);
							// this.getFiles(this.form1datacopy.id)
                            setTimeout(()=>{
                                this.InputItemData.files=this.uploadList
                            },300)
                        }
                    })
                }

                return false
            },
            downloadFile(guideId, file) {
                let url = this.fileUrl + '/file/' + file.id;
                this.$http.get(url, {
                    responseType: 'blob'      //告诉服务器我们需要的响应格式
                }).then((res) => {

                    const aLink = document.createElement("a");
                    let blob = new Blob([res.data], {
                        type: res.bodyBlob.type      //将会被放入到blob中的数组内容的MIME类型
                    });
                    aLink.href = URL.createObjectURL(blob)
                    aLink.download = file.fileName //标题
                    aLink.click()
                    document.body.appendChild(aLink)
                })
            },

            remove1(id,itemId) {
                let url = this.fileUrl + '/file/' + id;
                this.$http.delete(url).then((res) => {
                    this.getFiles(itemId)
                })
            },

            selectLocation(location) {
                this.form1datacopy.locationId = location.value;
                this.form1datacopy.location = location.label;
            },
            selectstdRank(stdRank) {
                this.form1datacopy.stdRankId = stdRank.value;
                this.form1datacopy.stdRank = stdRank.label;
            },
            selectAppStatus(appStatus) {
                this.form1datacopy.appStatusId = appStatus.value;
                this.form1datacopy.appStatus = appStatus.label;
            },
            beforeUploadOther(file) {
                this.files.push(file);
                return false;
            },
            deleteFile(index) {
                this.files.splice(index, 1);
            },
            setOrgId(data) {
                this.form1datacopy.constructionUnitId = data[data.length - 1];
            },
            setOrgName(data) {
                this.form1datacopy.constructionUnit = data;
            },
            deleteData(params) {
                let data = {
                    id:params.row.id
                }
                let url = Api.deletePunishInfoRecords;
                this.$http.delete(url, {params: data}).then((res) => {
                    if (res.data.status === 200) {
                        this.$Message.success('成功');
                        this.query()
                    } else if (res.data.status === 201) {
                        this.$Message.error(res.data.msg);
                    }
                }).catch(e => {
                    this.$Message.error('请求失败' + e);
                })
            },
            getSelectRows(rows) {
                this.deleteRows = rows;
            },
            get_uuid() {
                let s = [];
                let hexDigits = "0123456789abcdef";
                for (let i = 0; i < 36; i++) {
                    s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
                }
                s[14] = "4";
                s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);
                s[8] = s[13] = s[18] = s[23] = "-";

                let uuid = s.join("");
                let reg = new RegExp("-", "g");
                let a = uuid.replace(reg, "");
                return a;
            },
            
            addInfo() {
                this.view = false;
                this.uploadList = [];
                this.saveMod = false;
                this.form1datacopy = {
					fineLower:0,
					fineUpper:'零元整',
                };
                this.files = [];
                this.model1 = true;
                this.add = true;
            },
            pageChange(pageNum) {
                this.pagedata.currentPage = pageNum;
                this.query();
            },
            pageSizeChange(pageSize) {
                this.pagedata.pageSize = pageSize;
                this.query();
            },
            handleCancel() {
                this.form1datacopy = {};
                this.uploadList = [];
                this.model1 = false;
                this.model2=false
            },
            switchQuery(flag) {
                this.switchFlag = flag;
                if (!this.switchFlag) {
                    this.tableHeight = this.tableHeight + 44;
                } else {
                    this.tableHeight = this.tableHeight - 44;
                }
            },
            reset() {
                this.form1 = {};
                this.query();
            },
            query() {
                this.loading = true;
                let userId = sessionStorage('userId').getObject('userId').userId;
                let data = {
                    startPage: this.pagedata.currentPage,
                    size: this.pagedata.pageSize,
                    orgId: sessionStorage('userId').getObject('userId').companyId

                };
                data = Object.assign(data, JSON.parse(JSON.stringify(this.form1)));

                let url = Api.queryPunishInfoRecords;
                this.$http.get(url, {params: data}).then((res) => {
                    this.dataTable = res.data.data.data;
                    this.pagedata.total = res.data.data.totalSize;
                    this.loading = false;
                }).catch(e => {
                    this.$Message.error("数据获取失败")
                })
            },
            showData(data, flag) {
                this.loading1=true
                this.orgId = data.row.orgId;
                this.form1datacopy = JSON.parse(JSON.stringify(data.row));
				if(this.form1datacopy.id != undefined){
					this.getFiles(this.form1datacopy.id)
				}
                if (flag == 1) { //查看页面
					this.uploadList = []
                    this.view = true;
					if(this.form1datacopy.inspectionPersonnelFile != undefined ){
						this.getFiles1(this.form1datacopy.inspectionPersonnelFile,"1")
					}
                    if(this.form1datacopy.projectLeaderFile != undefined){
						this.getFiles1(this.form1datacopy.projectLeaderFile,"2")
					}
                    this.model2 = true;
                } else {//修改页面
                    this.view = false;
                    this.form1datacopy = JSON.parse(JSON.stringify(data.row));
                    this.saveMod = false;
                    this.add = false;
                    this.files = [];
                    this.model1 = true;
                }
            },
            submit(name) {
				if(this.form1datacopy.fineLower.toString().split(".")[0].length>10){
					this.$Message.error("罚款金额整数最长为十位数");
				}else{
					if(this.add){
						this.form1datacopy.id =  this.id;
					}else{
						this.form1datacopy.id = this.form1datacopy.id;
					}
					this.form1datacopy.orgId = sessionStorage('userId').getObject('userId').companyId;
					this.$refs[name].validate((valid) => {
					    this.form1datacopy.apsgNoticeItems = this.apsgNoticeItem
					    if (valid) {
					        this.buttonLoading = true
					        this.saveMod = true;
					        if (this.add) {
					            let userId = sessionStorage('userId').getObject('userId').userId;
					            let orgId = sessionStorage('userId').getObject('userId').orgInfo.orgId;
					            this.form1datacopy.createUsrId = userId;
					            this.form1datacopy.createOrgId = orgId;
					            this.$http.post(Api.savePunishInfoRecords, this.form1datacopy).then((res) => {
					                if (res.data.status === 200) {
					                    this.$Message.success('成功');
					                    this.model1 = false;
					                    this.saveMod = false;
					
					                    this.query()
					
					                } else if (res.data.status === 201) {
					                    this.$Message.error(res.data.msg);
					                    this.model1 = false;
					                }
									this.id = this.get_uuid();
					                this.buttonLoading = false
					            }).catch(e => {
					                this.model1 = false;
					                this.query();
					                this.buttonLoading = false
					                this.$Message.error("数据获取失败")
					            })
					        } else {
					            let userId = sessionStorage('userId').getObject('userId').userId;
					            let orgId = sessionStorage('userId').getObject('userId').orgInfo.orgId;
					            this.form1datacopy.updateUserId = userId;
					            this.form1datacopy.updateOrgId = orgId;
					            this.$http.post(Api.updatePunishInfoRecords, this.form1datacopy).then((res) => {
					                if (res.data.status === 200) {
					                    this.$Message.success('成功');
					                    this.saveMod = false;
					                    this.model1 = false;
					
					                    this.query()
					
					                } else if (res.data.status === 201) {
					                    this.$Message.error(res.data.msg);
					                    this.model1 = false;
										
					                }
					                this.buttonLoading = false
					            }).catch(e => {
					                this.model1 = false;
					                this.query();
					                this.buttonLoading = false
					                this.$Message.error("数据获取失败")
					            })
					        }
					    } else {
					        this.$Message.error('请填报完整!!');
					    }
					})
				}
				
            },
            formatDate(date, fmt) {
                if (/(y+)/.test(fmt)) {
                    fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
                }
                let o = {
                    'M+': date.getMonth() + 1,
                    'd+': date.getDate(),
                    'h+': date.getHours(),
                    'm+': date.getMinutes(),
                    's+': date.getSeconds()
                };
                for (let k in o) {
                    if (new RegExp(`(${k})`).test(fmt)) {
                        let str = o[k] + '';
                        fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? str : this.padLeftZero(str));
                    }
                }
                return fmt;
            },
            padLeftZero(str) {
                return ('00' + str).substr(str.length);
            },
            export(row){
                this.isSpin = true;
				let a = sessionStorage('userId').getObject('userId').orgInfo.orgName;
                this.$http.get(Api.downloadPunishRecords,{
                    params:{
						id:row.id,
						orgName:sessionStorage('userId').getObject('userId').orgInfo.orgName
					},
                    responseType: 'arraybuffer'
                }).then((res) => {
                    const aLink = document.createElement("a");
                    let blob = new Blob([res.data], {
                        type: "application/msword"
                    })
                    aLink.href = URL.createObjectURL(blob);
                    aLink.download = "安全环保处罚通知单.doc" //标题
                    aLink.click();
                    document.body.appendChild(aLink);
                    this.isSpin = false;
                }).catch(e => {
                    this.$Message.error("数据获取失败");
                    this.isSpin = false;
                })
            },
			//转换大写
			convertUpper () {
			  var num = this.form1datacopy.fineLower
			  var strOutput = "";
			  var strUnit = '仟佰拾亿仟佰拾万仟佰拾元角分';
			  num += "00";
			  var intPos = num.indexOf('.');
			  if (intPos >= 0)
			    num = num.substring(0, intPos) + num.substr(intPos + 1, 2);
			  strUnit = strUnit.substr(strUnit.length - num.length);
			  for (var i=0; i < num.length; i++)
			    strOutput += '零壹贰叁肆伍陆柒捌玖'.substr(num.substr(i,1),1) + strUnit.substr(i,1);
			  this.form1datacopy.fineUpper = strOutput.replace(/零角零分$/, '整').replace(/零[仟佰拾]/g, '零').replace(/零{2,}/g, '零').replace(/零([亿|万])/g, '$1').replace(/零+元/, '元').replace(/亿零{0,3}万/, '亿').replace(/^元/, "零元");
			},
			createEmptyDataToAdd(){
			  return {
			    fineLower:0,
			    fineUpper:'零元整',
			  }
			}
        },
        watch: {
            "model1": function (qw, er) {
                if (qw && this.model1) {
                    setTimeout(() => {
                    }, 100)
                }
            },

        },
    }
</script>

<style lang='css' scoped>
    @import '../../../index.css';
    .demo-spin-icon-load{
        animation: ani-demo-spin 1s linear infinite;
    }
    @keyframes ani-demo-spin {
        from { transform: rotate(0deg);}
        50%  { transform: rotate(180deg);}
        to   { transform: rotate(360deg);}
    }
</style>
